<template>
	<view class="content">
		<view class="content-bg">
			<u-navbar bgColor="transparent" titleStyle="color:#fff" title="我的工卡" leftIconColor="#fff" :autoBack="true"
				:placeholder="false">
				<view slot="right" style="color: #fff;" @click="gonavto('/pages/home/my_card/record/index')">转增记录</view>
			</u-navbar>
			<view class="content-box">
				<view style="height: 4vh;"></view>
				<view class="factory-box">
					<view class="factory-item" v-for="(item,index) in list" :key="index">
						<view class="new">余{{surplus}}张</view>
						<view class="item-top">
							<image :src="item.logo" mode=""></image>
							<view class="top-right">
								<view class="right-title">
									{{item.name}}
								</view>
								<view class="refund">
									<view class="refund-item way">
										返款方式
									</view>
									<view class="refund-item">
										每日返本返息
									</view>
								</view>
							</view>
						</view>
						<view class="item-num">
							<view class="num">
								<view>
									{{item.rate}}%
								</view>
								<view class="num-text">
									日产量
								</view>
							</view>
							<view class="num">
								<view>
									{{item.price}}
								</view>
								<view class="num-text">
									云矿石
								</view>
							</view>
							<view class="num">
								<view>
									{{item.day_rec}}
								</view>
								<view class="num-text">
									日收益
								</view>
							</view>
						</view>
						<view class="work">
							<view>
								工作时间{{item.days}}天
							</view>
							<view class="work-btn">
								<u-button color="#563AFD" type="primary" @click="goopen(item)" text="开启"></u-button>
								<view style="width: 40rpx;"></view>
								<u-button color="#563AFD" type="primary" text="转赠" @click="openTransfer(item)"></u-button>
							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" />
			</view>
		</view>
		<u-popup :show="show" mode="center" round="30rpx">
			<view class="transfer">
				<view class="transfer-box">
					<view class="transfer-title">
						转赠
					</view>
					<view class="content-title">
						转入人账户
					</view>
					<view class="entry">
						<u--input maxlength="16" border="none" color="#fff" v-model="account"
							placeholder="请输入转入人账户"></u--input>
					</view>
					<view class="content-title">
						支付密码
					</view>
					<view class="entry">
						<u--input maxlength="6" type="password" border="none" color="#fff" v-model="pass"
							placeholder="请输入支付密码"></u--input>
					</view>
					<view class="transfer-btn">
						<view class="btn">
							<u-button @click="cancelBtn" color="#eeeeee33" size="large" shape="circle" type="primary"
								text="取消"></u-button>
						</view>
						<view class="btn">
							<u-button @click="confirmBtn()"
								color="linear-gradient( 90deg, #513AFD 0%, #D333FB 38%, #E146E1 50%, #CA33FB 64%, #5239FD 100%)"
								size="large" shape="circle" type="primary" text="确定"></u-button>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-keyboard ref="uKeyboard" class="pwd-pop" @change="changePwd" @backspace="clearPwd" :show="showKeyboard"
			mode="number" :dot-enabled="false" :tooltip="false" default="">
			<view class="flex-between-center head-tab">
				<view class="title">验证支付密码</view>
				<view class="close-text" @click="closePwd">
					<u-icon name="close-circle" size="50rpx"></u-icon>
				</view>
			</view>
			<view style="display: flex;justify-content: center;">
				<u-code-input hairline size="43" color="#000" focus disabled-keyboard dot :space="22"
					borderColor="rgb(216, 216, 216)" v-model="password" :maxlength="6"></u-code-input>
			</view>
		</u-keyboard>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				surplus:0,
				show: false,
				account: '',
				password: '',
				pass: '',
				page: 1,
				list: [],
				status: 'loadmore',
				pwdList: [],
				showKeyboard: false,
				id: '',
			}
		},
		onShow() {
			this.page = 1
			this.postlist()
		},
		onReachBottom() {
			this.page++
			this.status = 'loading';
			this.postlist()
		},
		methods: {
			gonavto(url){
				uni.navigateTo({
					url:url
				})
			},
			closePwd() {
				this.showKeyboard = false;
				this.password = ""
				this.pwdList = []
			},
			goopen(item) {
				this.id = item.id
				this.showKeyboard = true
			},
			clearPwd() {
				console.log(1)
				if (this.password.length > 0) {
					this.pwdList = this.pwdList.slice(0, -1)
					this.password = this.password.substring(0, this.password.length - 1);
					console.log(this.pwdList)
				}
			},
			changePwd(e) {
				this.pwdList.push(e)
				if (this.pwdList.length > 6) return
				if (this.pwdList.length === 6) {
					this.password += this.pwdList[this.pwdList.length - 1];
					if (this.ok) return
					this.finish()
				} else {
					this.password += e;
				}
			},
			finish() {
				this.pwdList = []
				uni.showLoading({
					mask: true
				})
				let params = {
					id: this.id,
					password: this.password
				}
				this.$Request({
					method: 'POST',
					url: '/api/Trade/gongkai',
					data: params
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						uni.showToast({
							title: '开启成功！',
							icon: 'none'
						})
						this.password = ""
						this.showKeyboard = false;
						this.page = 1
						this.postlist()
					} else {
						this.password = ""
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			postlist() {
				let params = {
					page: this.page
				}
				this.$Request({
					method: 'POST',
					url: '/api/Trade/gongkaList',
					data: params
				}).then(res => {
					if (res.code == 1) {
						this.surplus = res.data.count
						if (res.data.list.length < 10) {
							this.status = 'nomore'
						}
						if (this.page == 1) {
							this.list = res.data.list
						} else {
							this.list = [...this.list, ...res.data.list]
						}
					} else {
						this.status = 'nomore'
					}
				})
			},
			openTransfer(item) {
				this.show = true
				this.id = item.id
			},
			confirmBtn(id) {
				if (this.account == '') {
					uni.showToast({
						title: '请输入转增人账号!',
						icon: 'none'
					})
					return
				}
				if (this.pass == '') {
					uni.showToast({
						title: '请输入支付密码!',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					mask:true
				})
				let params = {
					mobile: this.account,
					password: this.pass,
					type: 5,
					gongfenid:this.id
				}
				this.$Request({
					method: 'POST',
					url: '/api/Trade/energyTransfer',
					data: params
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.account = ''
						this.pass = ''
						this.show = false
						this.page = 1
						this.postlist()
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			cancelBtn() {
				this.show = false
				this.account = ''
				this.pass = ''
			}
		}
	}
</script>

<style>
	page {
		background: #1e0c4f;
	}
</style>
<style lang="scss" scoped>
	.pwd-pop {
		border-radius: 10px 10px 0 0;
		box-sizing: border-box;
		overflow: hidden;

		.head-tab {
			display: flex;
			width: 100%;
			box-sizing: border-box;
			justify-content: center;

			.title {
				color: #000;
				font-size: 18px;
				padding: 17px 0;
				font-weight: bold;
			}

			.close-text {
				position: absolute;
				right: 20rpx;
				top: 20rpx;
				color: #adaeb3;
			}
		}

		.pass-input-title {
			text-align: center;
			padding: 10rpx 0;
			color: #666;
			font-size: 26rpx;
		}

		.all-money {
			padding-bottom: 30rpx;
			margin-bottom: 20rpx;
			text-align: center;
			border-bottom: 2px solid #f5f5f5;
			font-size: 80rpx;
			font-family: "din";
			font-weight: bold;

			text {
				font-size: 28rpx;
				margin-left: 10rpx;
				font-weight: normal;
			}
		}

		.van-number-keyboard {
			width: 108%;
			margin-left: -4%;
			position: initial;
		}
	}

	/deep/ .u-keyboard {
		background-color: #fff;
		border-radius: 0 20rpx;
	}

	.content {
		.transfer {
			width: 686rpx;
			background: #1e0c4f;
			border-radius: 30rpx;
			overflow: hidden;

			.transfer-box {
				background-image: url('../../../static/factory/head-bg.png');
				background-repeat: no-repeat;
				background-size: 100% 279rpx;
				padding: 40rpx 30rpx;

				color: #fff;

				.transfer-title {
					font-size: 32rpx;
					font-weight: 600;
					padding: 0 30rpx;
					text-align: center;
				}

				.content-title {
					font-size: 28rpx;
					font-weight: 600;
					padding: 30rpx 0;
				}

				.entry {
					padding: 20rpx;
					background-color: rgba(238, 238, 238, 0.2);
					border-radius: 20rpx;
				}

				.transfer-btn {
					display: flex;
					justify-content: space-between;
					margin-top: 50rpx;

					.btn {
						width: 47%;
					}
				}
			}
		}

		.content-bg {
			background-image: url('../../../static/factory/head-bg.png');
			background-repeat: no-repeat;
			background-size: 100% 544rpx;
			min-height: 100vh;

			.content-box {
				padding: 30rpx;

				.factory-box {
					margin-top: 30rpx;

					.factory-item {
						position: relative;
						margin-top: 30rpx;
						background-color: rgba(255, 255, 255, .05);
						padding: 30rpx;
						border-radius: 20rpx;

						.new {
							position: absolute;
							right: 0;
							top: 0;
							background-color: rgba(255, 255, 255, .05);
							padding: 15rpx 20rpx;
							border-top-right-radius: 20rpx;
							border-bottom-left-radius: 20rpx;
							color: #F53CDE;
							font-size: 24rpx;
							font-weight: 600;
						}

						.item-top {
							display: flex;
							align-items: center;

							image {
								width: 110rpx;
								height: 110rpx;
							}

							.top-right {
								color: #FFFFFF;
								margin-left: 20rpx;

								.right-title {
									font-size: 32rpx;
									font-weight: 600;
								}

								.refund {
									margin-top: 20rpx;
									display: flex;
									font-size: 24rpx;
									background-color: rgba(255, 255, 255, .05);
									border-radius: 10rpx;
									overflow: hidden;

									.refund-item {
										padding: 10rpx 15rpx;
									}

									.way {
										background: linear-gradient(90deg, #513AFD 0%, #F42FF9 54%, #F85B9F 100%);
									}
								}
							}
						}

						.item-num {
							display: flex;
							justify-content: space-around;
							padding: 20rpx;
							background-color: rgba(255, 255, 255, .05);
							border-radius: 20rpx;
							color: #fff;
							margin-top: 30rpx;
							text-align: center;

							.num {
								font-size: 32rpx;
								font-weight: 600;

								text {
									font-size: 24rpx;
									font-weight: 400;
								}
							}

							.num-text {
								color: #999;
								font-size: 24rpx;
								margin-top: 15rpx;
							}
						}

						.work {
							display: flex;
							justify-content: space-between;
							align-items: center;
							margin-top: 30rpx;
							color: #999;
							font-size: 24rpx;

							text {
								font-weight: 600rpx;
								color: #F53CDE;
								font-size: 40rpx;
							}

							.work-btn {
								width: 340rpx;
								display: flex;
								align-items: center;
							}
						}
					}
				}
			}
		}
	}
</style>